<?php
session_start();

include_once("../lib/functions.php");
getProjectRootPath();
//die("DOC-ROOT: ".$_SERVER['DOCUMENT_ROOT']);
require_once($_SERVER['DOCUMENT_ROOT']."/updates/PostActions.php");
require_once($_SERVER['DOCUMENT_ROOT']."/lib/GenericCRUDOperations.php");

function array2json($arr) {
    if(function_exists('json_encode')) return json_encode($arr); //Lastest versions of PHP already has this functionality.
    $parts = array();
    $is_list = false;

    //Find out if the given array is a numerical array
    $keys = array_keys($arr);
    $max_length = count($arr)-1;
    if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {//See if the first key is 0 and last key is length - 1
        $is_list = true;
        for($i=0; $i<count($keys); $i++) { //See if each key correspondes to its position
            if($i != $keys[$i]) { //A key fails at position check.
                $is_list = false; //It is an associative array.
                break;
            }
        }
    }

    foreach($arr as $key=>$value) {
        if(is_array($value)) { //Custom handling for arrays
            if($is_list) $parts[] = array2json($value); /* :RECURSION: */
            else $parts[] = '"' . $key . '":' . array2json($value); /* :RECURSION: */
        } else {
            $str = '';
            if(!$is_list) $str = '"' . $key . '":';

            //Custom handling for multiple data types
            if(is_numeric($value)) $str .= $value; //Numbers
            elseif($value === false) $str .= 'false'; //The booleans
            elseif($value === true) $str .= 'true';
            else $str .= '"' . addslashes($value) . '"'; //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Object?)

            $parts[] = $str;
        }
    }
    $json = implode(',',$parts);
    
    if($is_list) return '[' . $json . ']';//Return numerical JSON
    return '{' . $json . '}';//Return associative JSON
}

$actionType=0;
if(isset($_POST["actiontype"]) && trim($_POST["actiontype"])!="" || strtolower(trim($_POST["actiontype"]))!="none" ){
    $postAction=new PostAction();
    //mean there is some action to perform
    $actionType=trim($_POST["actiontype"]);    
    $loggedInId=0;
    try {            
        //try to read all psted values
        if (isset($_SESSION["Allyfolio_User_ID"]) && !empty($_SESSION["Allyfolio_User_ID"])) {
            $loggedInId = trim($_SESSION["Allyfolio_User_ID"]);
        }
                        
        if($loggedInId >0 ){            
            switch($actionType){
                case 'add_cluster': //like                
                    try {
                        $clustername="";
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["cluster_name"]) && !empty($_POST["cluster_name"])) {
                            $clustername = trim($_POST["cluster_name"]);
                        }
                        
                        $taskResult= $objCrudOperation->AddCluster($clustername,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: AddCluster():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                case 'add_cluster_friend': // add friend to cluster
                    try {
                        $clusterid=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["clusterid"]) && !empty($_POST["clusterid"])) {
                            $clusterid = trim($_POST["clusterid"]);
                        }
                        if (isset($_POST["friendsid"]) && !empty($_POST["friendsid"])) {
                            //$friendsid = trim($_POST["friendsid"]);
                            if(strstr(trim($_POST["friendsid"]),",")){
                                $friendsid = explode(",",trim($_POST["friendsid"]));
                            }
                            else{
                                if(is_numeric(trim($_POST["friendsid"]))){
                                    $friendsid[0]=trim($_POST["friendsid"]);
                                }
                            }
                        }
                        $taskResult= $objCrudOperation->AddClusterFriend($clusterid,$loggedInId,$friendsid);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: AddClusterFriend():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                case 'remove_cluster_friend': // add friend to cluster
                    try {
                        $clusterid=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["clusterid"]) && !empty($_POST["clusterid"])) {
                            $clusterid = trim($_POST["clusterid"]);
                        }
                        if (isset($_POST["friendsid"]) && !empty($_POST["friendsid"])) {
                            //$friendsid = trim($_POST["friendsid"]);
                            if(strstr(trim($_POST["friendsid"]),",")){
                                $friendsid = explode(",",trim($_POST["friendsid"]));
                            }
                            else{
                                if(is_numeric(trim($_POST["friendsid"]))){
                                    $friendsid[0]=trim($_POST["friendsid"]);
                                }
                            }
                        }
                        $taskResult= $objCrudOperation->RemoveClusterFriend($clusterid,$loggedInId,$friendsid);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: RemoveClusterFriend():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                case 'follow_sources': // add friend to cluster
                    try {
                        $idtofollow=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["idtofollow"]) && !empty($_POST["idtofollow"])) {
                            $idtofollow = trim($_POST["idtofollow"]);
                        }
                        if (isset($_POST["followtype"]) && !empty($_POST["followtype"])) {
                            $followtypeid = trim($_POST["followtype"]);
                            
                        }
                        $taskResult= $objCrudOperation->FollowSourceOwner($idtofollow,$loggedInId,$followtypeid);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: RemoveClusterFriend():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                case 'mark_as_read_mine_notificaion':
                    try {
                        $idtomark=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["idtomark"]) && !empty($_POST["idtomark"])) {
                            $idtomark = trim($_POST["idtomark"]);
                        }
                        
                        $taskResult= $objCrudOperation->MarkAsReadNotification($idtomark,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: MarkAsReadNotification():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case 'get_emotions_list': // add friend to cluster
                    try {
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        $taskResult= $objCrudOperation->getEmotionsList();
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithJsonErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: getEmotionsList():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case 'get_emotions_cat_dlist': // add friend to cluster
                    try {
                        $emcatid=0;
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["emcatid"]) && !empty($_POST["emcatid"])) {
                            $emcatid = trim($_POST["emcatid"]);
                        }
                        if($emcatid>0){
                            $taskResult= $objCrudOperation->getEmotionsCatDList($emcatid);
                            switch ($taskResult["err_code"]) {
                                case 200:
                                    echo responseWithJsonErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                                default:
                                    echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                            }
                        }
                        else{
                            echo responseWithErrorCode("400","Bad Request");
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: getEmotionsCatDList():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case 'update_user_settings':
                    try {
                        $idtomark=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        $oUserInfoSettings= new UsersInfo();
                        $dob="0";
                        if (isset($_POST["first_name"]) && !empty($_POST["first_name"])) {
                            $oUserInfoSettings->first_name = trim($_POST["first_name"]);
                        }
                        if (isset($_POST["last_name"]) && !empty($_POST["last_name"])) {
                            $oUserInfoSettings->last_name = trim($_POST["last_name"]);
                        }
                        if (isset($_POST["display_name"]) && !empty($_POST["display_name"])) {
                            $oUserInfoSettings->display_name = trim($_POST["display_name"]);
                        }
                        if (isset($_POST["pemail"]) && !empty($_POST["pemail"])) {
                            $oUserInfoSettings->primary_email = trim($_POST["pemail"]);
                        }
                        if (isset($_POST["semail"]) && !empty($_POST["semail"])) {
                            $oUserInfoSettings->recovery_email = trim($_POST["semail"]);
                        }
                        if (isset($_POST["pwd"]) && !empty($_POST["pwd"])) {
                            $oUserInfoSettings->new_password = trim($_POST["pwd"]);
                        }
                        if (isset($_POST["location"]) && !empty($_POST["location"])) {
                            $oUserInfoSettings->user_location = trim($_POST["location"]);
                        }
                        if (isset($_POST["dob"]) && !empty($_POST["dob"]) && strstr($_POST["dob"],"-")) {
                            $oUserInfoSettings->user_dob = trim($_POST["dob"]);
                        }
                        
                        $taskResult= $objCrudOperation->updateUserInfo($oUserInfoSettings,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: updateUserInfo():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case 'update_userprivacy_settings':
                    try {
                        $idtomark=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        $settingsFor="";
                        $settingsValue=1;
                        
                        if (isset($_POST["sFor"]) && !empty($_POST["sFor"])) {
                            $settingsFor = trim($_POST["sFor"]);
                        }
                        
                        if (isset($_POST["iVal"])) {
                            $settingsValue = trim($_POST["iVal"]);
                        }
                        
                        $fieldname="";
                        switch($settingsFor){
                            case "contact_for_friendship":
                                $fieldname="contact_me_for_friendship";
                            break;
                            
                            case "search_on_dna":
                                $fieldname="search_on_dna";
                            break;
                                
                            case "email_setting":
                                $fieldname="email_address";
                            break;
                                
                            case "phone_no_settings":
                                $fieldname="phone_number";
                            break;
                                
                            case "address_settings":
                                $fieldname="address";
                            break;
                                
                            case "dob_settings":
                                $fieldname="dob";
                            break;
                                
                            case "fax_settings":
                                $fieldname="fax_no";
                            break;
                                
                            case "family_view_settings":
                                $fieldname="family";
                            break;
                                
                            case "blog_settings":
                                $fieldname="Blog_Setting";
                            break;
                                
                            case "voice_comment_settings":
                                $fieldname="voice_comment";
                            break;
                                
                            case "downlod_pic_setings":
                                $fieldname="download_pics";
                            break;
                            
                            case "block_permission_settings":
                                $fieldname="block_permission";
                            break;
                            
                            case "join_pages_notifications":
                                $fieldname="join_pages_notifications";
                            break;
                            
                            case "enclose_in_join_pages_notifications":
                                $fieldname="enclose_in_join_pages_notifications";
                            break;
                            
                            case "hide_notifications_from_cluster_ids":
                                $fieldname="hide_notifications_from_cluster_ids";
                            break;
                            case "chk_showD":
                                $fieldname="DOB_Date_Settings";
                            break;
                            case "chk_showM":
                                $fieldname="DOB_Month_Settings";
                            break;
                            case "chk_showY":
                                $fieldname="DOB_Year_Settings";
                            break;
                        }
                        
                        //echo "fieldname: ".$fieldname." settingsvalue: ".$settingsValue." userid: ".$loggedInId;
                        //die();
                        $taskResult= $objCrudOperation->updateUserPrivacySettings($fieldname,$settingsValue,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: updateUserPrivacySettings():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case "remove_my_account":
                    try {
                        $idtomark=0;
                        $objCrudOperation=new CRUDOperations();
                        $taskResult= $objCrudOperation->TemporaryDeleteAccount($loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: TemporaryDeleteAccount():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                
                case "delete_my_account":
                    try {
                        $idtomark=0;
                        $objCrudOperation=new CRUDOperations();
                        $taskResult= $objCrudOperation->PermanentDeleteAccount($loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: PermanentDeleteAccount():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;    
                    
                case "account_removed_feedback":
                    try {
                        $idtomark=0;
                        $objCrudOperation=new CRUDOperations();
                        $feedback_message="";
                        
                        if (isset($_POST["feedback_message"]) && !empty($_POST["feedback_message"])) {
                            $feedback_message = trim($_POST["feedback_message"]);
                        }
                        
                        $taskResult= $objCrudOperation->SendFeedBack("Account_Removed",$feedback_message,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: SendFeedBack():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;   
                    
                case 'unfollow_sources': // add friend to cluster
                    try {
                        $idtounfollow=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["idtounfollow"]) && !empty($_POST["idtounfollow"])) {
                            $idtounfollow = trim($_POST["idtounfollow"]);
                        }
                        $taskResult= $objCrudOperation->unFollowSourceOwner($idtounfollow,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: unFollowSourceOwner():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                case "post_reported_abuse":
                    try {
                        $idtomark=0;
                        $objCrudOperation=new CRUDOperations();                        
                        $poststatus=new PostStatus();
                        
                        $poststatus->IsHidden=0;
                        if (isset($_POST["report_post_id"]) && !empty($_POST["report_post_id"])) {
                            $idtomark=trim($_POST["report_post_id"]);
                        }
                        
                        
                        
                        if (isset($_POST["report_as_hidden"]) && !empty($_POST["report_as_hidden"]) && is_numeric($_POST["report_as_hidden"])) {
                            $poststatus->IsHidden=trim($_POST["report_as_hidden"]);
                        }
                        
                        if (isset($_POST["report_abuse_types"]) && !empty($_POST["report_abuse_types"])) {
                            $poststatus->ReportAbusetypes=trim($_POST["report_abuse_types"]);
                        }
                        if(strlen($poststatus->ReportAbusetypes)>0){
                            $poststatus->ReportAbuse="Report Abuse";
                        }
                        
                        //echo "post status: ".$poststatus->IsHidden;
                        if(is_numeric($idtomark)){
                            $taskResult= $objCrudOperation->ReportPostContent($poststatus,$idtomark,$loggedInId);
                            switch ($taskResult["err_code"]) {
                                case 200:
                                    echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                                default:
                                    echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                            }    
                        }
                        else{
                            $actionRes=$postAction->Failure;
                            $actionRes["msg"]="Bad Request";
                            echo $actionRes["msg"];
                        }
                        
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: SendFeedBack():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                 
                 case 'mark_as_read_mine_alerts':
                    try {
                        $alert_to_mark=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["alerttype"]) && !empty($_POST["alerttype"])) {
                            $alert_to_mark = trim($_POST["alerttype"]);
                        }
                        
                        $taskResult= $objCrudOperation->MarkAsReadAlerts($alert_to_mark,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: MarkAsReadAlerts():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;   
                    
                 case "download_pic_posted":
                    try {
                        
                        $filepathtodownload=0;
                        if (isset($_POST["filepath_download"]) && !empty($_POST["filepath_download"])) {
                            $filepathtodownload=trim($_POST["filepath_download"]);
                        }
                        downloadImageForUser($loggedInId,$filepathtodownload);                        
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: downloadImageForUser():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break; 
                 
                 case 'edit_post_loc': // add friend to cluster
                    try {
                        $idtoedit=0;
                        $postlocation="";
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["idtoedit"]) && !empty($_POST["idtoedit"])) {
                            $idtoedit = trim($_POST["idtoedit"]);
                        }
                        if (isset($_POST["ploc"]) && !empty($_POST["ploc"])) {
                            $postlocation = trim($_POST["ploc"]);
                        }
                        
                        $taskResult= $objCrudOperation->changePostLocation($idtoedit,$postlocation,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: changePostLocation():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
                 case 'get_mynotificationspopup': // add friend to cluster
                    try {
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        $uid=7;
                        $nMaxNotifyIDRead=0;
                        if (isset($_POST["requested_by_uid"]) && !empty($_POST["requested_by_uid"])) {
                            $uid = trim($_POST["requested_by_uid"]);
                        }
                        if (isset($_POST["nMaxNotifyIDRead"]) && !empty($_POST["nMaxNotifyIDRead"])) {
                            $nMaxNotifyIDRead = trim($_POST["nMaxNotifyIDRead"]);
                        }
                        if(is_numeric($uid)){
                            $taskResult= $objCrudOperation->getMyNotificationPopup($uid,$nMaxNotifyIDRead);
                            //print_r($taskResult["msg"]);
                            //die();
                            switch ($taskResult["err_code"]) {
                                case 200:
                                    if(is_array($taskResult["msg"]) && count($taskResult["msg"])>0){
                                        
                                        $taskResult["msg"]=array2json($taskResult["msg"]);
                                    }
                                    else{
                                        if(is_array($taskResult["msg"]) && count($taskResult["msg"])==0){
                                            $taskResult["msg"]="[]";
                                        }
                                    }
                                    echo responseWithJsonErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                                default:
                                    echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                    break;
                            }
                        }
                        else{
                            echo responseWithErrorCode(400,"Bad Request");
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: getEmotionsList():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                 case 'mark_as_read_activity_for_me':
                    try {
                        $idtomark=0;
                        $friendsid=array();
                        $objCrudOperation=new CRUDOperations();
                        if (isset($_POST["actid"]) && !empty($_POST["actid"])) {
                            $idtomark = trim($_POST["actid"]);
                        }
                        
                        $taskResult= $objCrudOperation->MarkAsReadActivity($idtomark,$loggedInId);
                        switch ($taskResult["err_code"]) {
                            case 200:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                            default:
                                echo responseWithErrorCode($taskResult["err_code"],$taskResult["msg"]);
                                break;
                        }
                    }
                    catch(Exception $ex){
                        $oLog->writeException('generic_crudoperations: MarkAsReadNotification():: \t'. $ex->getMessage(). "\n");
                        echo responseWithErrorCode("400",$ex->getMessage());
                    }
                    break;
                    
             }
        }
        else{
            $actionRes=$postAction->Failed_For_Invalid_Session;
            echo $actionRes["msg"];
        }
    
    }
    catch(Exception $ex){
        die("Exception in CRUD Operation".$ex->getMessage());
    } 
}


?>